<?php
namespace app\admin\controller;
// namespace app\index\module;
use app\common\controller\Adminbase;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;

//class Club extends Adminbase{
     class Club extends controller{
    /**
     * 俱乐部管理 分成模式
     * @return
     */
    public function club(){
        $uid = Session::get("uid");
        $type = Db::name("users")->where("id",$uid)->find();
        $auth = Db::name("auth_group")->where("id",$type['type'])->find();
        return view('club', ['auth' => $auth['title']]);
    }
    /**
     * 俱乐部管理 分成模式
     * @return
     */
    public function club_from(){
        $uid = Session::get("uid");
        $type = Db::name("users")->where("id",$uid)->find();
        $auth = Db::name("auth_group")->where("id",$type['type'])->find();
        return view('club_from', ['auth' => $auth['title']]);
    }
    /**
     * 俱乐部管理 分成模式
     * @return
     */
    public function club_conf_1(){

        return $this->fetch();
    }
    /**
     * 俱乐部管理 免费模式
     * @return
     */
    public function clubs(){
        $uid = Session::get("uid");
        $type = Db::name("users")->where("id",$uid)->find();
        $auth = Db::name("auth_group")->where("id",$type['type'])->find();
        return view('clubs', ['auth' => $auth['title']]);
    }
    /**
     * 俱乐部查询
     * @return
     */
    public function club_1(){

        return $this->fetch();
    }
    /**
     * 俱乐部商城配置
     * @return
     */
    public function Club_configure(){
        $club = model('clubModel');
        $club->Automatic_lower_frame();
        return $this->fetch();
    }
    /**
     * 俱乐部配置历史
     * @return
     */
    public function Club_configure_1(){

        return $this->fetch();
    }
    /**
     * 金币配置
     * @return
     */
    public function Club_goldcoin(){

        return $this->fetch();
    }
    /**
     * 金币配置（历史）
     * @return
     */
    public function Club_goldcoin_1(){

        return $this->fetch();
    }
    /**
     * 俱乐部创建
     * @return
     */
    public function club_establish(){
        $uid = Session::get("uid");
        $type = Db::name("users")->where("id",$uid)->find();
        $auth = Db::name("auth_group")->where("id",$type['type'])->find();
        return view('club_establish', ['auth' => $auth['title']]);
    }
    /**
     * 金币发放
     * @return
     */
    public function club_grant(){

        return $this->fetch();
    }
    /**
     * 金币配置
     * @return
     */
    public function Club_conf(){

        return $this->fetch();
    }
    /**
     * 会员卡商城
     * @return
     */
    public function club_vipcard(){

        return $this->fetch();
    }
    /**
     * 会员卡商城
     * @return
     */
    public function club_vipcard_1(){

        return $this->fetch();
    }
    /**
     * 俱乐部 会长昵称查询
     * @return
     */
    public function president_name(){
        $player_id= input("param.player_id");
        $data = [
            'app_id' =>APP_ID,
            'uid' =>$player_id,

        ];
        $data = json_encode($data);
        $url =USER_HTTP."api/get_info.php";
        $curl = new \Curl();
        $result = $curl->vpost($url,$data);
        $result = json_decode($result);

        return $result->data->nickname;
    }
    /**
     * 俱乐部查询(分成模式)
     * @return
     */
    public function Club_query_divided(){
        $create_time = input("param.create_time");
        $president_id = input("param.president_id");//会长ID
        $club_id = input("param.club_id");//俱乐部ID
        $club_name =  input("param.club_name");//俱乐部名称
        $club_status = input("param.club_status");//当前状态
        $area_id = input("param.area_id");//当前状态
        $senior_president = input("param.senior_president");//当前状态
        $where =[];
        if($create_time !=""){
            $create_time_start = $create_time." "."00:00:00";//创建时间开始
            $create_time_end = $create_time." "."23:59:59";//创建时间结束
            $where["create_time"] = array(array('Egt',$create_time_start),array('Elt',$create_time_end), 'and');
        }
        if($president_id != 0){
            $where["president_id"] =$president_id;
        }
        if($club_id != 0){
            $where["cid"] =$club_id;
        }
        if($club_name != ""){
            $where["club_name"] =base64_encode($club_name);
        }
        if($club_status != 2){
            $where["club_status"] =$club_status;
        }
        if($area_id != 0){
            $where["area_id"] =$area_id;
        }
        if($senior_president != ""){
            $where["senior_president"] =$senior_president;
        }
        $where['club_type'] = 0;
        $result = Db::name('club')
            ->where($where)
            ->order("create_time desc")
            ->select();
        foreach ($result as $key => $value) {
            $result[$key]['club_name'] = base64_decode($value['club_name']);
            $club_members_count = Db::name('user_club')
                ->where("club_id",$value['cid'])
                ->where('status',1)
                ->count();
            $result[$key]['number_people'] = $club_members_count.'/'.$value['max_club_members_count'];
            $vip = Db::name('user_vip')
                ->where("club_id",$value['cid'])
                ->count();
            $result[$key]['vip'] =$vip;
            $area =  Db::name('area')
                ->where("aid",$value['area_id'])
                ->find();
            $result[$key]['area_name'] = $area['area_name'];
        }
//        foreach ($result as $k => $v){
//            $player_id = $v['president_id'];
//            $club_id = $v['cid'];
//            $club = model('clubModel');
//            //获取用户资产(金币数)
//            $gold = $club->gold($player_id,$club_id,2);
//            //获取用户资产(钻石数)
//            $diamond = $club->diamond($player_id,$club_id);
//            $result[$k]['club_diamond'] = $diamond;
//            $result[$k]['club_gold'] = $gold;
//        }
        return json($result);

    }
    /**
     * 俱乐部查询(免費模式)
     * @return
     */
    public function Club_query_free(){
        $create_time = input("param.create_time");
        $president_id = input("param.president_id");//会长ID
        $club_id = input("param.club_id");//俱乐部ID
        $club_name =  input("param.club_name");//俱乐部名称
        $club_status = input("param.club_status");//当前状态
        $area_id = input("param.area_id");//当前状态
//        $senior_president = input("param.senior_president");//当前状态
        $where =[];
        if($create_time !=""){
            $create_time_start = $create_time." "."00:00:00";//创建时间开始
            $create_time_end = $create_time." "."23:59:59";//创建时间结束
            $where["create_time"] = array(array('Egt',$create_time_start),array('Elt',$create_time_end), 'and');
        }
        if($president_id != 0){
            $where["president_id"] =$president_id;
        }
        if($club_id != 0){
            $where["cid"] =$club_id;
        }
        if($club_name != ""){
            $where["club_name"] =json_encode($club_name);
        }
        if($club_status != 2){
            $where["club_status"] =$club_status;
        }
        if($area_id != 0){
            $where["area_id"] =$area_id;
        }
//        if($senior_president != ""){
//            $where["senior_president"] =$senior_president;
//        }
        $where['club_type'] = 1;
        $result = Db::name('club')
            ->where($where)
            ->order("create_time desc")
            ->select();
        foreach ($result as $key => $value) {
            $result[$key]['club_name'] = base64_decode($value['club_name']);
            $club_members_count = Db::name('user_club')
                ->where("club_id",$value['cid'])
                ->where('status',1)
                ->count();
            $result[$key]['number_people'] = $club_members_count.'/'.$value['max_club_members_count'];
            $area =  Db::name('area')
                ->where("aid",$value['area_id'])
                ->find();
            $model = model('clubModel');
            $yellow_diamond= $model->yellow_diamond($value['president_id'],$value['cid']);
            $result[$key]['yellow_diamond'] = $yellow_diamond;
            $result[$key]['area_name'] = $area['area_name'];
        }
        foreach ($result as $k => $v){
            $player_id = $v['president_id'];
            $club_id = $v['cid'];
            $club = model('clubModel');
            //获取用户资产(金币数)
            $gold = $club->gold($player_id,$club_id,2);
            //获取用户资产(钻石数)
            $diamond = $club->diamond($player_id,$club_id);
            $result[$k]['club_diamond'] = $diamond;
            $result[$k]['club_gold'] = $gold;
        }
        return json($result);

    }

    /**
     * 俱乐部查询(成员)
     * @return
     */
    public function Club_query_pepole(){
        $where =[];
        $club_id = input("param.club_id");
        $where['club_id'] = $club_id;
        $where['status'] = 1;
        $result = Db::name('user_club')
            ->where($where)
            ->select();
        foreach ($result as $key => $value) {
            $player_id = $value['player_id'];
            $club = model('clubModel');
            $president_name = $club->president_name($player_id);
            $vid = Db::name("user_vip")->where(["club_id"=>$club_id,"uid"=>$player_id,"vip_status"=>1])->find();
            if($vid){
                $vip_name = Db::name("vip_card")->where("vip_id",$vid['vid'])->find();
                $result[$key]['end_day'] = $vid['end_day'];
                $result[$key]['vip_name'] = $vip_name['name'];
            }else{
                $result[$key]['end_day'] = "-";
                $result[$key]['vip_name'] ="-";
            }

            $result[$key]['nickname'] = $president_name;

        }
        return json($result);

    }
    /**
     * 俱乐部查询(成员)
     * @return
     */
    public function Club_query_vip(){
        $where =[];
        $club_id = input("param.club_id");
        $time = date("Y-m-d H:i:s",time());
        $where['club_id'] = $club_id;
        // $where['end_day'] =array('Et',$time);
        $result = Db::name('user_vip')
            ->whereTime("end_day",'<',$time)
            ->where($where)
            ->select();
        foreach ($result as $key => $value) {
            $player_id = $value['uid'];
            $club = model('clubModel');
            $president_name = $club->president_name($player_id);
            $result[$key]['nickname'] = $president_name;
            $vip = Db::name("vip_card")->where("vip_id",$value['vip'])->find();
            $result[$key]['vip_name'] = $vip['name'];

        }
        return json($result);

    }
    /**
     * 俱乐部 创建
     * @return
     */
    public function Club_create(){

        $limitation = input("param.limitation");
        $club_type = input("param.club_type");
        $Senior_president = input("param.Senior_president");
        $rebate= input("param.rebate");
        $club_name =  base64_encode(input("param.club_name"));
        $player_id = input("param.player_id");
        $area = input("param.area");
        $game =array_unique(input("post.game/a"));
        $play_id = implode(",",$game);
        $room_rate = input("param.room_rate");
        do{
            do{
                do{
                    $cid = mt_rand(100000, 999999);
                    $number = (int)substr($cid,0,1);
                    if($number == 0){
                        $if = true;
                    }else{
                        $if = false;
                    }
                }while($if);
                $if_club = Db::name('club')
                    ->where('cid',$cid)
                    ->count();

            }while($if_club);
            $if_club_id = Db::name('pl_club_id')
                ->where('club_id',$cid)
                ->count();
        }while($if_club_id);

        $club = model('clubModel');
        $president_name = $club->president_name($player_id);
        if(empty($president_name)){
            return json(['code' => 0, 'url' => '', 'msg' => '玩家不存在']);
        }
        $result = $club->create_club($player_id,$club_name,$president_name,$limitation,$cid,$club_type,$area,$Senior_president,$rebate,$play_id,$room_rate);
        $club_id = Db::name("club")->order('create_time', 'desc')->find();
        $opera_time = date("Y-m-d H:i:s",time());
        $opera_pepole = Session::get("username");//操作人
        $opera_type = 1;//1 创建俱乐部
        $old_date = input("param.old_date");
        $new_date = input("param.new_date");
        $data = [
            'club_id' =>$club_id['cid'],//俱乐部id
            'opera_time' =>$opera_time,//操作时间
            'opera_pepole'=>$opera_pepole,//操作人
            'club_name'=>$club_name,//俱乐部名
            'opera_type'=>$opera_type,//操作类型
            'player_id'=>$player_id,//创建人id
            'old_date'=>$old_date,//原数据
            'new_date'=>$new_date,//新数据

        ];
        $record_result = $club->record($data);
        $message_url =USER_HTTP."api/get_batch_info.php";
        $message_data = [
            'app_id'=>APP_ID,
            'uid'=>$club_id['president_id'],
        ];
        $message_data = json_encode($message_data);
        $curl = new \Curl();
        $message_result = $curl->vpost($message_url,$message_data);
        $message_obj = json_decode($message_result);
        if(!empty($message_obj->data)){
            $nickname = $message_obj->data[0]->nickname;
        }
        if($result){
            $area_name = Db::name("area")->where("aid",$area)->find();
            $club_count =Db::name('club')->where('club_status',1)->select();
            $send_data = [
                'club_id'=>$club_id['cid'],//俱乐部名
                'club_name'=>base64_decode($club_id['club_name']),//俱乐部名
                'user_id'=>$club_id['president_id'],
                'role_name'=>$nickname,
                'club_region_id'=>$area,
                'club_region_name'=>$area_name['area_name'],
                'event_type'=>'create',//创建或解散create/dissolve
                'club_num'=>count($club_count),//本操作之后的俱乐部数量
            ];
            if($club_type == 0){
                $send_data['club_mode'] ='free';// club_mode 俱乐部模式 free免费/divide分成
            }else{
                $send_data['club_mode'] ='divide';
            }
            $event = 'club_create_dissolve';
            $send = model('clubModel');
            $send->send($event,$send_data);


            return json(['code' => 1, 'url' => '', 'msg' => '俱乐部创建成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '俱乐部创建失败']);
        }
    }
// 		public function ceshi(){
//             do{
//                $cid = mt_rand(10000, 99999);
//                do{
//                    explode();
//                }while($if_club);
//                $if_club = Db::name('club')
//                    ->where('cid',$cid)
//                    ->count();
//            }while($if_club);
//         }
    /**
     * 俱乐部 修改
     * @return
     */
    public function Club_modify(){
        $club_id = input("param.club_id");//俱乐部id
        $club_name = base64_encode(input("param.club_name"));//俱乐部昵称
        $president_id = input("param.president_id");//俱乐部会长id
//      $president_name = input("param.president_name");//俱乐部会长名
        $max_club_members_count = input("param.max_club_members_count");//俱乐部人数上限
        $club_diamond = input("param.club_diamond");//俱乐部返利
        $club_gold = input("param.club_gold");//俱乐部金币数
        $Senior_president = input("param.Senior_president");
        $rebate= input("param.rebate");
        $room_rate= input("param.room_rate");
        $game =input("post.game/a");
//        $play_id = implode(",",$game);
//        print_r($play_id);die;
        $type =1;
        $w =[];
        $w['player_id']=$president_id;
        $w['club_id']=$club_id;
        $w['status'] = 1;
        $Members =Db::name("user_club")->where($w)->find();
        if(empty($Members)){
            return json(['code' => 0, 'url' => '', 'msg' => '该玩家不是俱乐部成员']);
        }
        $message_url =USER_HTTP."api/get_batch_info.php";
        $message_data = [
            'app_id'=>APP_ID,
            'uid'=>$president_id,
        ];
        $message_data = json_encode($message_data);
        $curl = new \Curl();
        $message_result = $curl->vpost($message_url,$message_data);
        $message_obj = json_decode($message_result);
        if(!empty($message_obj->data)){
            $president_name = $message_obj->data[0]->nickname;
        }
//        $h = [];
//        $h['player_id']=$president_id;
//        $h['club_id']=$club_id;
//        $embers =Db::name("user_club")->where($h)->find();
//        if(!empty($embers)){
//           $status =  $embers['status'];
//           if($status != 1){
//               Db::name("user_club")->where($h)->update(["status"=>1]);
//           }
//        }
        $opera_time = date("Y-m-d H:i:s",time());
        $opera_pepole = Session::get("username");//操作人
        $opera_type = 2;//2 修改俱乐部
        $record_data = [
            'club_id' =>$club_id,//俱乐部id
            'opera_time' =>$opera_time,//操作时间
            'opera_pepole'=>$opera_pepole,//操作人
            'club_name'=>$club_name,//俱乐部名
            'opera_type'=>$opera_type,//操作类型
            'old_date'=>input("param.old_date"),//原数据
            'new_date'=>input("param.new_date"),//新数据

        ];
        $club = model('clubModel');
        $record_result = $club->record($record_data);

        $data = [

            'club_name'=>$club_name,
            'president_id'=>$president_id,
            'president_name'=>$president_name,
            'max_club_members_count'=>$max_club_members_count,
            'room_rate'=>$room_rate

            // 'senior_president'=>$Senior_president,
//			'club_gold'=>$club_gold,
//			'club_diamond'=>$club_diamond,

        ];
        if(!empty($game)){
            $game_id = implode(",",array_unique($game));
            $data['play_id'] = $game_id;
        }
        if($Senior_president != ""){
            $data['senior_president'] = $Senior_president;
            $data['rebate'] = $rebate;
        }else{
            $data['senior_president'] = null;
            $data['rebate'] = null;
        }
        if($type == 1){
            $data['pin_drilling_ratio'] = $club_diamond;
        }

        $club = model('clubModel');
        $result = $club->club_modify($club_id,$data,$club_diamond,$president_id);
//        Db::name()
        if($result){
            return json(['code' => 1, 'url' => '', 'msg' => '俱乐部修改成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '俱乐部修改失败']);
        }

    }
    /**
     * 俱乐部 解散
     * @return
     */
    public function Club_dissolution(){
        $club_id = input("param.club_id");//俱乐部id
        $club_name = base64_encode(input("param.club_name"));//俱乐部昵称

        $opera_time = date("Y-m-d H:i:s",time());
        $opera_pepole = Session::get("username");//操作人
        $opera_type = 3;//3 解散俱乐部
        $record_data = [
            'club_id' =>$club_id,//俱乐部id
            'opera_time' =>$opera_time,//操作时间
            'opera_pepole'=>$opera_pepole,//操作人
            'club_name'=>$club_name,//俱乐部名
            'opera_type'=>$opera_type,//操作类型
            'old_date'=>input("param.old_date"),//原数据
            'new_date'=>input("param.new_date"),//新数据

        ];
        $club = model('clubModel');
        $record_result = $club->record($record_data);
        $result = Db::name("club")
            ->where("cid",$club_id)
            ->update([
                'club_status'=>0
            ]);
        $club = Db::name("club")->where('cid',$club_id)->find();
        $message_url =USER_HTTP."api/get_batch_info.php";
        $message_data = [
            'app_id'=>APP_ID,
            'uid'=>$club['president_id'],
        ];
        $message_data = json_encode($message_data);
        $curl = new \Curl();
        $message_result = $curl->vpost($message_url,$message_data);
        $message_obj = json_decode($message_result);
        if(!empty($message_obj->data)){
            $nickname = $message_obj->data[0]->nickname;
        }
        Db::name("user_last_club")->where("club_id",$club_id)->delete();
        Db::name("user_club")->where("club_id",$club_id)->delete();
        if($result){
            $area_name = Db::name("area")->where("aid",$club['area_id'])->find();
            $club_count =Db::name('club')->where('club_status',1)->select();
            $send_data = [
                'club_id'=>$club['cid'],//
                'club_name'=>base64_decode($club['club_name']),//俱乐部名
                'user_id'=>$club['president_id'],
                'role_name'=>$nickname,
                'club_region_id'=>(string)$club['area_id'],
                'club_region_name'=>$area_name['area_name'],
                'event_type'=>'dissolve',//创建或解散create/dissolve
                'club_num'=>count($club_count),//本操作之后的俱乐部数量
            ];
            if($club['club_type'] == 0){
                $send_data['club_mode'] ='free';// club_mode 俱乐部模式 free免费/divide分成
            }else{
                $send_data['club_mode'] ='divide';
            }
            $event = 'club_create_dissolve';
            $send = model('clubModel');
            $send->send($event,$send_data);
            //发送邮件

            $recipient =[$club['president_id']];
            // $recipient = array_push($recipient,);
            $name = base64_decode($club['club_name']);
            $data = [
                'appid'=>APP_ID,//游戏服id
                'sender'=>0,//发收人
                'recipient'=>$recipient,//接收人
                'title'=>'解散',
                'content'=>'您所在的俱乐部【'.$name.'】已经解散，请重新申请俱乐部！',
                'send_time'=>date("Y-m-d H:i:s",time()),
                'goods'=>"",
                'sender_type'=>1
            ];

            $data = json_encode($data);
            $url =HTTP."api/email_add.php";
            $curl = new \Curl();
            $result = $curl->vpost($url,$data);
            $json = json_decode($result);
            // print_r($result);

            return json(['code' => 1, 'url' => '', 'msg' => '俱乐部成功解散']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '俱乐部解散失败']);
        }


    }
    /**
     * 俱乐部 人数
     * @return
     */
    public function Club_people(){
        $club_id = input("param.club_id");
        $club = Db::name("club")
            ->where("cid",$club_id)
            ->select();

        return json($club);

    }
    /**
     * 俱乐部 操作记录 条件查询
     * @return
     */
    public function Club_record(){
        $time = input("param.time");
        $opera_type = input("param.opera_type");
        $where = [];
        if($time != "" ){
            $start_time = substr($time,0,10)." "."00:00:00";
            $end_time = substr($time,13)." "."23:59:59";
            $where["opera_time"] = array(array('Egt',$start_time),array('Elt',$end_time), 'and');
        }
        if($opera_type != 0){
            $where['opera_type'] = $opera_type;
        }
//        $where['opera_type']  = ['neq',5];
        $club = Db::name("club_operation")
            ->where($where)
            ->order('id desc')
            ->select();
        foreach ($club as $key => $value) {
            $club[$key]['club_name'] = base64_decode($value['club_name']);
        }
        return json($club);
    }
    /**
     * 俱乐部创建 历史记录 条件查询
     * @return
     */
    public function Club_create_record(){
        $start_time = input("param.start_time");
        $end_time = input("param.end_time");
        $player_id = input("param.player_id");
        $where = [];
        if($start_time != "" && $end_time != ""){
            $where["create_time"] = array(array('Egt',$start_time),array('Elt',$end_time), 'and');
        }
        if($player_id != 0){
            $where['player_id'] = $player_id;
        }
        $where["opera_type"] = 1;
        $club = Db::name("club_operation")
            ->where($where)
            ->select();

        return json($club);
    }
    /**
     * 俱乐部创建 历史记录 （默认显示10条）
     * @return
     */
    public function create_record_limit(){
//    	$club = Db::name("club_operation")
//    			->where('opera_type',1)
//                ->order('id desc')
//    			->limit(10)
//    			->select();

//        $where["opera_type"] = 1;
        $club = Db::query('select * from tb_club_operation where opera_time>DATE_SUB(CURDATE(), INTERVAL 6 MONTH) AND opera_type=1  ORDER BY opera_time DESC ');
        foreach ($club as $key => $value) {
            $club[$key]['club_name'] = base64_decode($value['club_name']);
        }

        return json($club);
    }
    /**
     * 俱乐部配置（抽水率）
     * @return
     */
    public function Club_configuration(){
        $cid = input("param.cid");
        $percentage = input("param.percentage");
        $percentage_up_area = input("param.percentage_up_area");
        $percentage_down_area = input("param.percentage_down_area");
        $data = [
            'percentage'=>$percentage,//抽水比例
            'percentage_up_area'=>$percentage_up_area,//抽水上线
            'percentage_down_area'=>$percentage_down_area,//抽水下线
        ];
        $club = Db::name("club")
            ->where("cid",$cid)
            ->update($$data);

        return $club;
    }
    /**
     * 俱乐部金币库存（查询）
     * @return
     */
    public function Club_gold_number(){
        $cid = input("param.cid");
        $club = Db::name("club")
            ->field("cid,club_name,player_id,president_name")
            ->where("cid",$cid)
            ->find();
        if($club){
            $club['club_name'] = base64_decode($club['club_name']);
        }
        //获取用户资产
        $assets_url =USER_HTTP."api/get_player_property.php";
        $assets_data = [
            'app_id'=>APP_ID,
            'uid'=>$club['player_id'],
        ];
        $assets_data = json_encode($assets_data);
        $curl = new \Curl();
        $assets_result = $curl->vpost($assets_url,$assets_data);
        $assets_obj = json_decode($assets_result);
//        print_r($assets_obj);
        $gold = 0;
        $gold_arr = [];
        foreach ($assets_obj->data as $key => $value) {
            $str = $value->property_type;
            $array=explode('_', $str);
            if($array[0] == $cid){
                if($array[1] == 2){
                    $gold_arr[] =$value;
                }else{
                    $gold_arr[] =[];
                }
            }else{
                $gold_arr[] =[];
            }
        }
        $gold_arr = array_filter($gold_arr);
        if(count($gold_arr)>=1){
            foreach ($gold_arr as $g_k => $g_v){
                if(!empty($g_v)){
                    $gold = 0;
                    $gold+= $g_v->property_num+$g_v->freeze_num;
                }
            }
        }else{
            $gold = 0;
        }
        $club['club_gold'] = $gold;

        return json($club);
    }
    /**
     * 俱乐部金币库存（发放）
     * @return
     */
    public function Club_gold_issued(){
        $cid = input("param.cid");
        $club_gold = input("param.club_gold");
        $club_name =base64_encode(input("param.club_name"));
//        $gold =  Db::name("club")
//                ->field("club_gold")
//                ->where("cid",$cid)
//                ->find();
//    	$data = [
//    		'club_gold'=>$club_gold+$gold['club_gold']
//    	];
        $player_id = Db::name('club')
            ->where("cid",$cid)
            ->find();
//    	$club = Db::name("club")
//    			->where("cid",$cid)
//    			->update($data);
        $property_type = $cid.'_'.'2';
        //增加用户金币（俱乐部）
        $assets_url =USER_HTTP."api/raise_player_property.php";
        $assets_data = [
            'app_id'=>APP_ID,
            'uid'=>$player_id['player_id'],
            'property_type'=>$property_type,
            'property_num'=>$club_gold
        ];
        $assets_data = json_encode($assets_data);
        $curl = new \Curl();
        $assets_result = $curl->vpost($assets_url,$assets_data);
        $assets_obj = json_decode($assets_result);
        if($assets_obj->code == 0){
            $opera_time = date("Y-m-d H:i:s",time());
            $opera_pepole = Session::get("username");//操作人
            $opera_type = 5;//5 发放金币
            $data = [
                'opera_time' =>$opera_time,//操作时间
                'opera_pepole'=>$opera_pepole,//操作人
                'club_name'=>$club_name,//俱乐部名
                'opera_type'=>$opera_type,//操作类型
                'number_gold'=>$club_gold,//发放金币数量
                'club_id'=>$cid,

            ];
            $club = model('clubModel');
            $record_result = $club->record($data);

            if($club){
                return json(['code' => 1, 'url' => '', 'msg' => '金币发放成功']);
            }else{
                return json(['code' => 0, 'url' => '', 'msg' => '金币发放失败']);
            }
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '金币发放失败']);
        }

    }
    /**
     * 俱乐部金币库存（发放记录）
     * @return
     */
    public function gold_issued_record(){
        $start_time = input("param.start_time");
        $end_time = input("param.end_time");
        if($start_time =="" && $end_time == ""){
            $starTime = date('Y-m-d', strtotime('-7 days'))." "."00:00:00";
            $endTime = date('Y-m-d', time())." "."23:59:59";
        }else{
            $start_time = input("param.start_time")." "."00:00:00";
            $end_time = input("param.end_time")." "."23:59:59";
        }
        $where["opera_time"] = array(array('Egt',$start_time),array('Elt',$end_time), 'and');
        $where["opera_type"] = 5;
        $club = Db::name("club_operation")
            ->where($where)
            ->order("id desc")
            ->select();
        foreach ($club as $key => $value) {
            $club[$key]['club_name'] = base64_decode($value['club_name']);
        }
        return json($club);
    }
    /**
     * 商城配置（添加）
     * @return
     */
    public function President_mall_configuration(){
        $goods_position = input("param.goods_position");//商品位置
        $number_diamonds = input("param.number_diamonds");//钻石数量
        $price = input("param.price")*100;//价格
        $start_time = input("param.start_time");//开始时间
        $end_time = input("param.end_time");//截止时间
        $sales_inventory = input("param.sales_inventory");//销售库存
        $exclusive_goods = input("param.exclusive_goods");//是否为专属商品（0 否 1是）
        $club_id = input("param.club_id");//俱乐部id
        $goods_type = input("param.goods_type");//商城类型
        $hot_sale = input("param.hot_sale");//是否热卖
        $vip_id= input("param.vip_id");//是否热卖
        $Give = input("param.Give");
        // $area =array_unique(input("post.data/a"));
        //添加商品到数据库
        $data = [
            "goods_position" => $goods_position,
            'goods_number' => $number_diamonds,
            'price' => $price,
            'give'=>$Give,
//			'start_time' => $start_time,
//			'end_time' => $end_time,
            'exclusive' => $exclusive_goods,
            'club_id' => $club_id,
            'goods_count' => $sales_inventory,
            'goods_type' => $goods_type,
            'hot_sale' => $hot_sale,
            // 'area_id'=>$area

        ];
        if(!empty($area)){
            $area_id = implode(",",array_unique($area));
            $data['area_id'] = $area_id;
        }
        if($start_time !="" && $end_time !=""){
            $data['start_time'] = $start_time;
            $data['end_time'] = $end_time;
        }
        if($goods_type == 10004){
            $data['vip_id'] = $vip_id;
        }
        $club = model('clubModel');
        $result = $club->president_configuration($data);

        if($result){
            //写入操作记录
            $goods_id = Db::name("club_shop")->order('id', 'desc')->find();
            $opera_time = date("Y-m-d H:i:s",time());
            $opera_pepole = Session::get("username");//操作人
            $opera_type = '添加商品';//修改商品
            $goods_id = $goods_id;
            $belongs = 1;

            $opera_data = [
                'opera_time' =>$opera_time,//操作时间
                'opera_pepole'=>$opera_pepole,//操作人
                'opera_type'=>$opera_type,//操作类型
                'goods_id'=>$goods_id['id'],//商品id
                'belongs'=>$belongs,
                "goods_position" => $goods_position,
                'number' => $number_diamonds,
                'price' => $price,
//                'start_time' => $start_time,
//                'end_time' => $end_time,
                'sales_inventory' => $sales_inventory,
                'exclusive_goods' => $exclusive_goods,
                'club_id' => $club_id,
                'goods_type' => $goods_type,
                'hot_sale' => $hot_sale,


            ];
            if($start_time !="" && $end_time !=""){
                $opera_data['start_time'] = $start_time;
                $opera_data['end_time'] = $end_time;
            }
            if($goods_type == 10004){
                $opera_data['vip_id'] = $vip_id;
            }
            $club = model('clubModel');
            $opera = $club->mall_record($opera_data,$start_time,$end_time);
            return json(['code' => 1, 'url' => '', 'msg' => '商品添加成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '商品添加失败']);
        }

    }
    /**
     * 会长商城配置（修改）
     * @return
     */
    public function President_mall_modify(){
        $id = input("param.goods_id");//商品id
        $goods_position = input("param.goods_position");//商品位置
        $number_diamonds = input("param.number_diamonds");//钻石数量
        $price = input("param.price")*100;//价格
        $start_time = input("param.start_time");//开始时间
        $end_time = input("param.end_time");//截止时间
        $exclusive_goods = input("param.exclusive_goods");//是否为专属商品（0 否 1是）
        $club_id = input("param.club_id");//俱乐部id
        $sales_inventory = input("param.sales_inventory");//销售库存
        $goods_type = input("param.goods_type");//商城类型
        $hot_sale = input("param.hot_sale");//是否热卖
        $vip_id= input("param.vip_id");
        $Give = input("param.Give");
        $area =input("post.data/a");
//         print_r($area);die;
        $data = [
            "goods_position" => $goods_position,
            'goods_number' => $number_diamonds,
            'price' => $price,
            'give'=>$Give,
//			'start_time' => $start_time,
//			'end_time' => $end_time,
            'goods_count' => $sales_inventory,
            'exclusive' => $exclusive_goods,
            'club_id' => $club_id,
//            'goods_type' => $goods_type,
            'hot_sale' => $hot_sale,

        ];
        if(!empty($area)){
            $area_id = implode(",",array_unique($area));
            $data['area_id'] = $area_id;
        }

        if($goods_type == 10004){
            $data['vip_id'] = $vip_id;
        }
        if($start_time !="" && $end_time !=""){
            $data['start_time'] = $start_time;
            $data['end_time'] = $end_time;
        }else{
            $data['start_time'] = null;
            $data['end_time'] = null;
        }
        $club = model('clubModel');
        $result = $club->president_modify($id,$data);

        if($result){
            $opera_time = date("Y-m-d H:i:s",time());
            $opera_pepole = Session::get("username");//操作人
            $opera_type = '修改商品';//修改商品
            $goods_id = $id;
            $belongs = 1;

            $opera_data = [
                'opera_time' =>$opera_time,//操作时间
                'opera_pepole'=>$opera_pepole,//操作人
                'opera_type'=>$opera_type,//操作类型
                'goods_id'=>$goods_id,//商品id
                'belongs'=>$belongs,
                "goods_position" => $goods_position,
                'number' => $number_diamonds,
                'price' => $price,
//                    'start_time' => $start_time,
//                    'end_time' => $end_time,
                'sales_inventory' => $sales_inventory,
                'exclusive_goods' => $exclusive_goods,
                'goods_type' => $goods_type,
                'club_id' => $club_id,
                'hot_sale' => $hot_sale,

            ];
            if($start_time !="" && $end_time !=""){
                $opera_data['start_time'] = $start_time;
                $opera_data['end_time'] = $end_time;
            }
            if($goods_type == 10004){
                $opera_data['vip_id'] = $vip_id;
            }
            $club = model('clubModel');
            $opera = $club->mall_record($opera_data,$start_time,$end_time);
            return json(['code' => 1, 'url' => '', 'msg' => '商品修改成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '商品修改失败']);
        }

    }
    /**
     * 会长商城配置（显示）
     * @return
     */
    public function President_goods_display(){
        $goods = [];
        $goods_type = input("param.goods_type");
        // $goods_type = 10001;
        $uid = Session::get("uid");
        $area = Db::name("users")->where("id",$uid)->find();
        $area_arr =explode(',',$area['area_id']);
        $result = Db::name("club_shop")
            ->where('goods_type',$goods_type)
            ->select();
        foreach ($result as $key => $value) {
            $result[$key]["price"] = $value["price"]/100;
            if($value['end_time'] == ""){
                $result[$key]["time"] = "永久";
            }else{
                $result[$key]["time"] = $value['start_time'].' - '. $value['end_time'];
            }
            if( $value["goods_count"] == -1){
                $result[$key]["goods_count"] = "不限";
            }
        }
        foreach ($result as $key => $value) {
            $area_id =explode(',',$value['area_id']);
//            print_r($area_id);
            foreach ($area_arr as $k=>$v){
                $aid = $v;
                if(in_array($aid,$area_id)){
                    $goods[] = $value;
//                    unset($result[$k]);
                }
            }

        }
        $out = array();
        foreach ($goods as $key=>$value) {
            if (!in_array($value, $out)){
                $out[$key] = $value;
            }
        }
        $out = array_values($out);
//            print_r($out);die;
        return json($result);
//
    }
    /**
     * 会长商城配置（商品下架）
     * @return
     */
    public function President_goods_mshelves(){
        $id = input("param.id");//商品id
        $goods_position = input("param.goods_position");//商品位置
        $number_diamonds = input("param.number_diamonds");//钻石数量
        $price = input("param.price")*100;//价格
        $start_time = input("param.start_time");//开始时间
        $end_time = input("param.end_time");//截止时间
        $sales_inventory = input("param.sales_inventory");//销售库存
        $exclusive_goods = input("param.exclusive_goods");//是否为专属商品（0 否 1是）
        $club_id = input("param.club_id");//俱乐部id
        $hot_sale = input("param.hot_sale");//是否热卖
        $goods_type = input("param.goods_type");
        $vip_id= input("param.vip_id");
        $status = 0;//商品状态
        $result = Db::name("club_shop")
            ->where("id",$id)
            ->update([
                "status"=>$status
            ]);
        if($result){
            //写入操作记录
            $opera_time = date("Y-m-d H:i:s",time());
            $opera_pepole = Session::get("username");//操作人
            $opera_type = '商品下架';//修改商品
            $goods_id = $id;
            $belongs = 1;

            $opera_data = [
                'opera_time' =>$opera_time,//操作时间
                'opera_pepole'=>$opera_pepole,//操作人
                'opera_type'=>$opera_type,//操作类型
                'goods_id'=>$id,//商品id
                'belongs'=>$belongs,
                "goods_position" => $goods_position,
                'number' => $number_diamonds,
                'price' => $price,
//                'start_time' => $start_time,
//                'end_time' => $end_time,
                'sales_inventory' => $sales_inventory,
                'exclusive_goods' => $exclusive_goods,
                'club_id' => $club_id,
                'goods_type' => $goods_type,
                'hot_sale' => $hot_sale,


            ];
            if($goods_type == 10004){
                $opera_data['vip_id'] = $vip_id;
            }
            $club = model('clubModel');
            $opera = $club->mall_record($opera_data,$start_time,$end_time);
            return json(['code' => 1, 'url' => '', 'msg' => '商品已成功下架']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '商品已下架失败']);
        }

    }
    /**
     * 会长商城配置（商品上架）
     * @return
     */
    public function President_goods_shelves(){
        $id = input("param.id");//商品id
        $goods_position = input("param.goods_position");//商品位置
        $number_diamonds = input("param.number_diamonds");//钻石数量
        $price = input("param.price")*100;//价格
        $start_time = input("param.start_time");//开始时间
        $end_time = input("param.end_time");//截止时间
        $sales_inventory = input("param.sales_inventory");//销售库存
        $exclusive_goods = input("param.exclusive_goods");//是否为专属商品（0 否 1是）
        $club_id = input("param.club_id");//俱乐部id
        $hot_sale = input("param.hot_sale");//是否热卖
        $goods_type = input("param.goods_type");
        $vip_id= input("param.vip_id");
        $status = 1;//商品状态
        $result = Db::name("club_shop")
            ->where("id",$id)
            ->update([
                "status"=>$status
            ]);
        if($result){
            $opera_time = date("Y-m-d H:i:s",time());
            $opera_pepole = Session::get("username");//操作人
            $opera_type = '商品上架';//修改商品
            $goods_id = $id;
            $belongs = 1;

            $opera_data = [
                'opera_time' =>$opera_time,//操作时间
                'opera_pepole'=>$opera_pepole,//操作人
                'opera_type'=>$opera_type,//操作类型
                'goods_id'=>$id,//商品id
                'belongs'=>$belongs,
                "goods_position" => $goods_position,
                'number' => $number_diamonds,
                'price' => $price,
//                'start_time' => $start_time,
//                'end_time' => $end_time,
                'sales_inventory' => $sales_inventory,
                'exclusive_goods' => $exclusive_goods,
                'club_id' => $club_id,
                'goods_type' => $goods_type,
                'hot_sale' => $hot_sale,

            ];
            if($goods_type == 10004){
                $opera_data['vip_id'] = $vip_id;
            }
            $club = model('clubModel');
            $opera = $club->mall_record($opera_data,$start_time,$end_time);
            return json(['code' => 1, 'url' => '', 'msg' => '商品上架成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '商品上架失败']);
        }

    }
    /**
     * 会长商城配置（商品删除）
     * @return
     */
    public function President_goods_del(){
        $id = input("param.id");//商品id
        $goods_position = input("param.goods_position");//商品位置
        $number_diamonds = input("param.number_diamonds");//钻石数量
        $price = input("param.price")*100;//价格
        $start_time = input("param.start_time");//开始时间
        $end_time = input("param.end_time");//截止时间
        $sales_inventory = input("param.sales_inventory");//销售库存
        $exclusive_goods = input("param.exclusive_goods");//是否为专属商品（0 否 1是）
        $club_id = input("param.club_id");//俱乐部id
        $hot_sale = input("param.hot_sale");//是否热卖
        $goods_type = input("param.goods_type");
        $vip_id= input("param.vip_id");
        $result = Db::name("club_shop")
            ->where("id",$id)
            ->delete();
        if($result){
            $opera_time = date("Y-m-d H:i:s",time());
            $opera_pepole = Session::get("username");//操作人
            $opera_type = '商品删除';//修改商品
            $goods_id = $id;
            $belongs = 1;

            $opera_data = [
                'opera_time' =>$opera_time,//操作时间
                'opera_pepole'=>$opera_pepole,//操作人
                'opera_type'=>$opera_type,//操作类型
                'goods_id'=>$id,//商品id
                'belongs'=>$belongs,
                "goods_position" => $goods_position,
                'number' => $number_diamonds,
                'price' => $price,
//                'start_time' => $start_time,
//                'end_time' => $end_time,
                'sales_inventory' => $sales_inventory,
                'exclusive_goods' => $exclusive_goods,
                'club_id' => $club_id,
                'goods_type' => $goods_type,
                'hot_sale' => $hot_sale,

            ];
            if($goods_type == 10004){
                $opera_data['vip_id'] = $vip_id;
            }
            $club = model('clubModel');
            $opera = $club->mall_record($opera_data,$start_time,$end_time);
            return json(['code' => 1, 'url' => '', 'msg' => '商品已成功删除']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '商品已删除失败']);
        }

    }
    /**
     * 金币商城配置（商品下架）
     * @return
     */
    public function gold_goods_mshelves(){
        $id = input("param.id");//商品id
        $goods_position = input("param.goods_position");//商品位置
        $gold_number = input("param.gold_number");//金币数量
        $price = input("param.price")*100;//价格
        $give = input("param.give");
        $hot_sale = input("param.hot_sale");//是否热卖
        $status = 0;//商品状态
        $result = Db::name("gold_mall")
            ->where("id",$id)
            ->update([
                "status"=>$status
            ]);
        if($result){
            $opera_time = date("Y-m-d H:i:s",time());
            $opera_pepole = Session::get("username");//操作人
            $opera_type = '商品下架';//修改商品
            $goods_id = $id;
            $belongs = 2;

            $opera_data = [
                'opera_time' =>$opera_time,//操作时间
                'opera_pepole'=>$opera_pepole,//操作人
                'opera_type'=>$opera_type,//操作类型
                'goods_id'=>$id,//商品id
                'belongs'=>$belongs,
                'goods_position'=>$goods_position,
                'number'=>$gold_number,
                'give'=>$give,
                'hot_sale' => $hot_sale,
                'price'=>$price

            ];
            $club = model('clubModel');
            $opera = $club->mall_record($opera_data);
            return json(['code' => 1, 'url' => '', 'msg' => '商品已成功下架']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '商品已下架失败']);
        }

    }
    /**
     * 金币商城配置（商品上架）
     * @return
     */
    public function gold_goods_shelves(){
        $id = input("param.id");//商品id
        $goods_position = input("param.goods_position");//商品位置
        $gold_number = input("param.gold_number");//金币数量
        $price = input("param.price")*100;//价格
        $give = input("param.give");
        $status = 1;//商品状态
        $result = Db::name("gold_mall")
            ->where("id",$id)
            ->update([
                "status"=>$status
            ]);
        if($result){
            $opera_time = date("Y-m-d H:i:s",time());
            $opera_pepole = Session::get("username");//操作人
            $opera_type = '商品上架';//修改商品
            $goods_id = $id;
            $belongs = 2;

            $opera_data = [
                'opera_time' =>$opera_time,//操作时间
                'opera_pepole'=>$opera_pepole,//操作人
                'opera_type'=>$opera_type,//操作类型
                'goods_id'=>$id,//商品id
                'belongs'=>$belongs,
                'goods_position'=>$goods_position,
                'number'=>$gold_number,
                'give'=>$give,
                'price'=>$price

            ];
            $club = model('clubModel');
            $opera = $club->mall_record($opera_data);
            return json(['code' => 1, 'url' => '', 'msg' => '商品上架成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '商品上架失败']);
        }

    }
    /**
     * 金币商城配置
     * @return
     */
    public function club_gold(){
        $goods_position = input("param.goods_position");//商品位置
        $gold_number = input("param.gold_number");//金币数量
        $price = input("param.price")*100;//价格
        $give = input("param.give");//赠送金币数量

        $data = [
            'goods_position'=>$goods_position,
            'gold_number'=>$gold_number,
            'price'=>$price,
            'give'=>$give,
        ];
        $club = model('clubModel');
        $gold_mall = $club->club_mall_gold($data);
        if($gold_mall){
            $id = Db::name("gold_mall")->order('id', 'desc')->find();
            $opera_time = date("Y-m-d H:i:s",time());
            $opera_pepole = Session::get("username");//操作人
            $opera_type = '添加商品';//修改商品
            $goods_id = $id['id'];
            $belongs = 2;

            $opera_data = [
                'opera_time' =>$opera_time,//操作时间
                'opera_pepole'=>$opera_pepole,//操作人
                'opera_type'=>$opera_type,//操作类型
                'g_goods_id'=>$goods_id,//商品id
                'belongs'=>$belongs,
                'goods_position'=>$goods_position,
                'number'=>$gold_number,
                'give'=>$give,
                'price'=>$price



            ];
            $club = model('clubModel');
            $opera = $club->mall_record($opera_data);
            return json(['code' => 1, 'url' => '', 'msg' => '金币商城配置成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '金币商城配置失败']);
        }

    }
    /**
     * 金币商城配置(修改)
     * @return
     */
    public function club_gold_modify(){
        $id = input("param.id");//商品位置
        $goods_position = input("param.goods_position");//商品位置
        $gold_number = input("param.gold_number");//金币数量
        $price = input("param.price")*100;//价格
        $give = input("param.give");//赠送金币数量
        $data = [

            'goods_position'=>$goods_position,
            'gold_number'=>$gold_number,
            'price'=>$price,
            'give'=>$give,
        ];
        $club = model('clubModel');
        $result = $club->gold_modify($id,$data);
        if($result){
            $opera_time = date("Y-m-d H:i:s",time());
            $opera_pepole = Session::get("username");//操作人
            $opera_type = '修改商品';//
            $belongs = 2;

            $opera_data = [
                'opera_time' =>$opera_time,//操作时间
                'opera_pepole'=>$opera_pepole,//操作人
                'opera_type'=>$opera_type,//操作类型
                'g_goods_id'=>$id,//商品id
                'belongs'=>$belongs,
                'goods_position'=>$goods_position,
                'number'=>$gold_number,
                'give'=>$give,
                'price'=>$price

            ];
            $club = model('clubModel');
            $opera = $club->mall_record($opera_data);
            return json(['code' => 1, 'url' => '', 'msg' => '金币商城修改成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '金币商城修改失败']);
        }

    }
    /**
     * 金币商城配置(信息)
     * @return
     */
    public function club_gold_messsage(){
        $result = Db::name("gold_mall")
            ->select();
        foreach ($result as $key => $value) {
            $result[$key]["price"] = $value["price"]/100;
        }
        return json($result);

    }

    /**
     * 金币商城配置（商品删除）
     * @return
     */
    public function gold_goods_del(){
        $id = input("param.id");//商品id
        $goods_position = input("param.goods_position");//商品位置
        $gold_number = input("param.gold_number");//金币数量
        $price = input("param.price")*100;//价格
        $give = input("param.give");//

        $result = Db::name("gold_mall")
            ->where("id",$id)
            ->delete();
        if($result){
            $opera_time = date("Y-m-d H:i:s",time());
            $opera_pepole = Session::get("username");//操作人
            $opera_type = '商品删除';//
            $belongs = 2;

            $opera_data = [
                'opera_time' =>$opera_time,//操作时间
                'opera_pepole'=>$opera_pepole,//操作人
                'opera_type'=>$opera_type,//操作类型
                'g_goods_id'=>$id,//商品id
                'belongs'=>$belongs,
                'goods_position'=>$goods_position,
                'number'=>$gold_number,
                'give'=>$give,
                'price'=>$price

            ];
            $club = model('clubModel');
            $opera = $club->mall_record($opera_data);
            return json(['code' => 1, 'url' => '', 'msg' => '商品已成功删除']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '商品已删除失败']);
        }

    }
    /**
     * 抽水(显示)
     * @return
     */
    public function ratio_display(){

        $result = Db::name("club_ratio")
            ->find();
        return json($result);

    }
    /**
     * 抽水配置
     * @return
     */
    public function ratio(){
        $ratio_currency_back_drill = input("param.ratio_currency_back_drill");//商品id
        $pumping_ratio = input("param.pumping_ratio");//商品id
        $upper_limit = input("param.upper_limit");//
        $lower_limit = input("param.lower_limit");//
        $data = [
            'ratio_currency_back_drill'=>$ratio_currency_back_drill,
            'pumping_ratio'=>$pumping_ratio,
            'upper_limit'=>$upper_limit,
            'lower_limit'=>$lower_limit,

        ];
        Db::name('club_ratio')->delete(true);
        $result = Db::name("club_ratio")
            ->insert($data);
        if($result){
            return json(['code' => 1, 'url' => '', 'msg' => '配置成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '配置失败']);
        }

    }
    /**
     * 会长商品 操作记录
     * @return
     */
    public function President_operations(){
        $time = input("param.time");//
        $goods_id = input("param.goods_id");//
        $goods_type = input("param.goods_type");//
        $where = [];
        if($time !=""){
            $start_time = substr($time,0,10)." "."00:00:00";;
            $end_time = substr($time,13)." "."23:59:59";;
            $where["opera_time"] = array(array('Egt',$start_time),array('Elt',$end_time), 'and');
        }
        if($goods_id != 0){
            $where["goods_id"] = $goods_id;
        }
        $where['belongs'] = 1;
        $where['goods_type'] = $goods_type;
        $result = Db::name('mall_opera')
            ->where($where)
            ->order("id desc")
            ->select();
        return $result;

    }
    /**
     * 金币商品 操作记录
     * @return
     */
    public function gold_operations(){
        $time = input("param.time");//
        $goods_id = input("param.goods_id");//
        $where = [];
        if($time !=""){
            $start_time = substr($time,0,10)." "."00:00:00";;
            $end_time = substr($time,13)." "."23:59:59";;
            $where["opera_time"] = array(array('Egt',$start_time),array('Elt',$end_time), 'and');
        }
        if($goods_id != 0){
            $where["g_goods_id"] = $goods_id;
        }
        $where['belongs'] = 2;
        $result = Db::name('mall_opera')
            ->where($where)
            ->order("id desc")
            ->select();
        return $result;

    }
    /**
     * 会长商品 详情查询
     * @return
     */
    public function President_details(){
        $id = input("param.id");//
        $goods_id = input("param.goods_id");//
        $goods_type = input("param.goods_type");//

        $where['id'] = $id;
        $where['goods_id'] = $goods_id;
        $where['goods_type'] = $goods_type;
        $result = Db::name('mall_opera')
            ->where($where)
            ->order("id desc")
            ->find();
        return $result;

    }
    /**
     * 金币商品 详情查询
     * @return
     */
    public function gold_details(){
        $id = input("param.id");//
        $goods_id = input("param.goods_id");//

        $where['id'] = $id;
        $where['g_goods_id'] = $goods_id;
        $result = Db::name('mall_opera')
            ->where($where)
            ->order("id desc")
            ->find();
        return $result;

    }
    //vip卡添加
    public function vip_add(){
        $data = [];
        $vip_id = input("param.vip_id");
        $name = input("param.name");
        $number_day = input("param.day");
        $diamond_consumption = input("param.diamond");
        $price_upper_limit = input("param.price_upper_limit")*100;
        $price = input("param.price")*100;
        $type = input("param.type");

        $data = [
            'vip_id' =>$vip_id,
            'name' =>$name,
            'number_day' =>$number_day,
            'diamond_consumption' =>$diamond_consumption,
            'price_upper_limit' =>$price_upper_limit,
            'price' =>$price,
            'type'=>$type
        ];
        $file = request()->file('f');
        if($file){
            $info = $file->move(ROOT_PATH . 'public/static/img');
            $a=$info->getSaveName();
            $imgp= str_replace("\\","/",$a);
            $imgpath='static/img/'.$imgp;
            $banner_img= $imgpath;
            $response = array();
            if($info){
                $response = true;
            }else{
                $response = false;
            }
            $club_icon =  $imgpath;
            $data['icon'] = $club_icon;
        }else{
            $response = true;
        }

        $result = Db::name("vip_card")
            ->insert($data);
        if($result){
            return json(['code' => 1, 'url' => '', 'msg' => 'vip卡配置成功','isSuccess'=>$response]);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => 'vip卡配置失败','isSuccess'=>$response]);
        }
    }
    //vip卡修改
    public function vip_save(){
        $data = [];
        $id = input("param.id");
        $vip_id = input("param.vip_id");
        $name = input("param.name");
        $number_day = input("param.day");
        $diamond_consumption = input("param.diamond");
        $price = input("param.price")*100;
        $price_upper_limit = input("param.price_upper_limit")*100;

        $data = [
            'vip_id' =>$vip_id,
            'name' =>$name,
            'number_day' =>$number_day,
            'diamond_consumption' =>$diamond_consumption,
            'price' =>$price,
            'price_upper_limit' =>$price_upper_limit,
        ];
        $file = request()->file('f');
        if($file){
            $info = $file->move(ROOT_PATH . 'public/static/img');
            $a=$info->getSaveName();
            $imgp= str_replace("\\","/",$a);
            $imgpath='static/img/'.$imgp;
            $banner_img= $imgpath;
            $response = array();
            if($info){
                $response = true;
            }else{
                $response = false;
            }
            $club_icon =  $imgpath;
            $data['icon'] = $club_icon;
        }else{
            $response = true;
        }

        $result = Db::name("vip_card")
            ->where('id',$id)
            ->update($data);
        if($result){
            return json(['code' => 1, 'url' => '', 'msg' => 'vip卡修改成功','isSuccess'=>$response]);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => 'vip卡修改失败','isSuccess'=>$response]);
        }
    }
    public function vip_message(){
        $result = Db::name('vip_card')
            ->select();
        foreach ($result as $k =>$v){
            $result[$k]['price_upper_limit'] = $v['price_upper_limit']/100;
            $result[$k]['price'] = $v['price']/100;
        }
        return json($result);

    }
    public function vip_del(){
        $id = input("param.id");
        $result = Db::name('vip_card')
            ->where("id",$id)
            ->delete();
        if($result){
            return json(['code' => 1, 'url' => '', 'msg' => 'vip卡删除成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => 'vip卡删除失败']);
        }

    }
    /**
     * 地区列表
     * @return
     */
    public function area(){
        $result = Db::name('area')
            ->select();
        return json($result);
    }
    /**
     * 所属区域
     * @return
     */
    public function Own_area(){
        $id = input("param.id");
        $result = Db::name('users')
            ->where("id",$id)
            ->find();
        $area = explode(',',$result['area_id']);
        $arr = [];
        foreach ($area as $k =>$v){
            $name = Db::name("area")
                ->where("aid",$v)
                ->find();
            array_push($arr,$name['area_name']);

        }
        return json($arr);
    }
    /**
     * vip卡信息
     * @return
     */
    public function vip_id(){
        $result = Db::name('vip_card')
            ->select();

        return json($result);
    }
    /**
     * 地区倍数
     * @return
     */
    public function Regional_multiple_list(){
        $result = Db::name('area')
            ->select();
        foreach ($result as $k=>$v){
            $result[$k]['multiple'] = $v['multiple']/100;
        }
        return json($result);
    }
    /**
     * 地区倍数 (修改)
     * @return
     */
    public function Regional_multiple_save(){
        $aid = input("param.id");
        $multiple = input("param.multiple")*100;
//        print_r($aid);die;
        $result = Db::name('area')
            ->where('aid',$aid)
            ->update(
                ['multiple'=>$multiple]
            );
        if($result || $result===0){
            return json(['code' => 1, 'url' => '', 'msg' => '修改成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '修改失败']);
        }
    }
    /**
     * 上限倍数
     * @return
     */
    public function multiple_list(){

        $result = Db::name('multiple')
            ->find(
            );
        return json($result['multiple']);
    }
    /**
     * 上限倍数
     * @return
     */
    public function multiple(){
        $multiple = input("param.multiple");
        Db::name('multiple')->delete(true);
        $result = Db::name('multiple')
            ->insert(
                ['multiple'=>$multiple]
            );
        if($result){
            return json(['code' => 1, 'url' => '', 'msg' => '设置成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' => '设置失败']);
        }
    }
    //玩法规则
    public function Game_rules(){
        $id = input("param.id");
        $result = Db::name("play")
            ->where("id",$id)
            ->find();
        $a =json_decode($result['play']);
        return json($a->checks);
    }
    //房间创建
    public function room_options(){
//        $arr = '{"room_type":"123","model_name":"123","wanfa":["3","","2","21","22","26","1"],"fangfei":"playerPoints_2t","consume":"600"}';
        $club_id= input("param.club_id");
        $arr = input("param.arr");
        $arr = (array)json_decode($arr);
        do{
            $room_id = mt_rand(10000, 99999);
            $if_club = Db::name('room_options')
                ->where('room_id',$room_id)
                ->count();
        }while($if_club);
        $data = [
            'club_id'=>$club_id,
            'room_name'=>$arr['model_name'],
            'options'=>json_encode($arr['wanfa']),
            'diamond'=>$arr['consume'],
            'room_rate'=>$arr['fangfei'],
            'room_type'=>$arr['room_type'],
            'room_id'=>$room_id
        ];
        $result = Db::name("room_options")
            ->insert($data);
        if($result){
            return json(['code' => 1, 'url' => '', 'msg' => '创建成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' =>'创建失败']);
        }

    }
    //房间列表
    public function room_list(){
        $club_id = input("param.club_id");
        $result = Db::name("room_options")
            ->where("club_id",$club_id)
            ->select();
        return $result;

    }
    //房间修改
    public function room_Modify(){
        $id = input("param.id");
        $arr = input("param.arr");
        $arr = (array)json_decode($arr);
        $data = [
            'room_name'=>$arr['model_name'],
            'options'=>json_encode($arr['wanfa']),
            'diamond'=>$arr['consume'],
            'room_rate'=>$arr['fangfei'],
        ];
        $result = Db::name("room_options")
            ->where("id",$id)
            ->update($data);
        if($result !== false) {
            return json(['code' => 1, 'url' => '', 'msg' => '修改成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' =>'修改失败']);
        }

    }
    //房间删除
    public function room_del(){
        $id = input("param.id");
        $result = Db::name("room_options")
            ->where("id",$id)
            ->delete();
        if($result){
            return json(['code' => 1, 'url' => '', 'msg' => '删除成功']);
        }else{
            return json(['code' => 0, 'url' => '', 'msg' =>'删除失败']);
        }

    }
    //游戏列表
    public function game_list(){
        $goods = [];
        $club_id = input("param.clubId");
//        $club_id =62336;
        $game = Db::name("club")->where("cid",$club_id)->find();
        $play = explode(",",$game['play_id']);
        $result = Db::name("play")
            ->field("id,name")
            ->select();
        foreach ($result as $k =>$v){
            $play_id = $v['id'];
            if(in_array($play_id,$play)){
                $goods[] = $v;
            }
        }
        return json($goods);

    }

    //房费模式
    public function room_rate(){
        $club_id = input("param.clubId");
//        $club_id = 369024;
        $club_name = Db::name("club")->where("cid",$club_id)->find();
        if($club_name['room_rate']==0){
            $data= [
                "id" => $club_name['room_rate'],
                "name" =>'均摊',
            ];
        }else{
            $data= [
                "id" => $club_name['room_rate'],
                "name" =>'大赢家',
            ];
        }
        return json($data);

    }
    /**
     * 钻石消耗限制
     * @return
     */
    public function Play_limit(){
        $where = [];
        $people = input("param.people");//人数
        $ring = input("param.ring");//圈数
        $bureau = input("param.bureau");//局数
        $Pid= input("param.pid");//所属玩法
        $club_id = input("param.clubId");
        $area_id =  Db::name("club")->where("cid",$club_id)->find();
        $where['people'] = $people;
        $where['pid'] = $Pid;
        if($ring != ""){
            $where['ring'] =  $ring ;
        }
        if($bureau != ""){
            $where['bureau'] =  $bureau ;
        }
        $table_diamond =  Db::name("diamond")
            ->where($where)
            ->find();
        $area = Db::name("area")
            ->where('aid',$area_id['area_id'])
            ->find();
        $area_multiple = $area['multiple']/100;
        $multiple = Db::name("multiple")
            ->find();

        $area_multiple = $area['multiple']/100;
        $Upper_limit = $table_diamond['diamond']*$area_multiple*$multiple['multiple'];
        $lower_limit= $table_diamond['diamond']*$area_multiple;
        $result = new \stdClass();
        $result->Upper_limit = $Upper_limit;
        $result->lower_limit = $lower_limit;
        return json($result);
//        print_r($table_diamond);
    }
    /**
     * 钻石消耗
     * @return
     */
    public function Play(){
        $where = [];
        $people = input("param.people");//人数
        $ring = input("param.ring");//圈数
        $bureau = input("param.bureau");//局数
        $Pid= input("param.pid");//所属玩法
        $area_id= input("param.area_id");//地区
        $where['people'] = $people;
        $where['pid'] = $Pid;
        if($ring != ""){
            $where['ring'] =  $ring ;
        }
        if($bureau != ""){
            $where['bureau'] =  $bureau ;
        }
        $table_diamond =  Db::name("diamond")
            ->where($where)
            ->find();
        $area = Db::name("area")
            ->where('aid',$area_id)
            ->find();
        // $diamond = $table_diamond['diamond']*$area['multiple'];
        return json($table_diamond['diamond']);
        // print_r($table_diamond['diamond']);
    }

}